<?php
$this->breadcrumbs=array(
	TextbooksModule::t('Change Campus') => Yii::app()->createUrl('/textbooks/selectUniversity'),
	TextbooksModule::t($university->name) => Yii::app()->createUrl('/textbooks/department/index',array('university_id'=>$university->id)),
	TextbooksModule::t('Post book'),
);?>

<div class="row">
	<div class="span12">
		<?php /** @var BootActiveForm $form */
		$form = $this->beginWidget('bootstrap.widgets.BootActiveForm', array(
			'id' => 'textbook-user-course-taking-form',
			'type' => 'horizontal',
			'enableAjaxValidation' => false,
			'enableClientValidation' => true,
			'clientOptions'=>array('validateOnSubmit'=>true),
			'htmlOptions' => array(
				'class'=>'modal-form h-textbooks-form-post-book h-textbooks-course-form-add-course',
				'enctype'=>'multipart/form-data',
			),
		)); ?>
			<?php echo $form->hiddenField($model, 'thumbnail', ''); ?>
			<fieldset>
				<legend>Post a new book in <?php echo CHtml::encode($university->name); ?></legend>
				<?php // echo $form->errorSummary($model); ?>
				<?php echo $form->dropDownListRow($model, 'department_id', CMap::mergeArray(array(''=>'[Select one]'), CHtml::listData($departments, 'id', 'name')), array('class'=>'span3 h-textbooks-select-department-id')); ?>
				<?php echo $form->textFieldRow($model, 'isbn', array('class'=>'span3')); ?>
				<div class="h-textbooks-div-hidden" <?php if (!($model->department_id && isset($_POST['TextbookBook']))) echo 'style="display:none"'; ?>>
					<div class="control-group <?php if ($model->getError('course_id')) echo 'error'; ?>">
						<?php echo $form->labelEx($model,'course_id',array('class'=>'control-label')); ?>
						<div class="controls">
							<?php $this->widget('CAutoComplete', array(
								'model' => $model,
								'attribute' => 'course_id',
								'url' => array('/textbooks/course/suggestCourses'),
								'max' => 10,
								'minChars' => 1,
								'delay' => 500,
								'matchCase' => false,
								'htmlOptions' => array('class'=>'span3 h-textbooks-input-course-name'),
							)); ?>
							<?php echo $form->error($model,'course_id'); ?>
						</div>
					</div>
					<?php echo $form->textFieldRow($model, 'title', array('class'=>'span3')); ?>
					<?php echo $form->textFieldRow($model, 'price', array('class'=>'span3')); ?>
					<?php echo $form->textFieldRow($model, 'author', array('class'=>'span3')); ?>
					<?php echo $form->textFieldRow($model, 'description', array('class'=>'span3')); ?>
					<?php echo $form->textFieldRow($model, 'phone', array('class'=>'span3')); ?>
					<?php echo $form->textFieldRow($model, 'email', array('class'=>'span3')); ?>
					<?php echo $form->fileFieldRow($model, 'image'); ?>
					<div class="control-group h-textbooks-book-thumbnail" style="display:none">
						<label class="control-label">Thumbnail</label>
						<div class="controls">
							<img alt="Thumbnail"/>
						</div>
					</div>
				</div>
				<div class="form-actions">
					<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'button', 'type'=>'primary', 'label'=>'Next', 'icon'=>'arrow-right white', 'htmlOptions'=>(!($model->department_id && isset($_POST['TextbookBook'])))?array('class'=>'h-textbooks-books-link-search-isbn'):array('disabled'=>true, 'style'=>'display:none'))); ?>
					<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Post this book', 'icon'=>'ok white', 'htmlOptions'=>(!($model->department_id && isset($_POST['TextbookBook'])))?array('disabled'=>true, 'style'=>'display:none'):array())); ?>
				</div>
			</fieldset>
		<?php $this->endWidget(); ?>
	</div>
</div>